﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Common.Entities
{
	public class DetailedProjectInfo
	{
		public string AssemblyName { get; set; }
		public string ProjectName { get; set; }
		public string RootNamespace { get; set; }
		public string ToolVersion { get; set; }
		public string ProductVersion { get; set; }
		public string OutputType { get; set; }
		public string TargetFrameworkVersion { get; set; }
		public string TargetFrameworkProfile { get; set; }
		public string PublishUrl { get; set; }
		public string InstallUrl { get; set; }
		public bool ContainsResourceFile { get; set; }
		public string ProjectRootPath { get; set; }

		public List<ReferenceInfo> References { get; set; }
		public List<ProjectFileInfo> CompiledFiles { get; set; }
		public List<PageInfo> Pages { get; set; }
		public List<EmbeddedResources> ResoucesFiles { get; set; }

		public DetailedProjectInfo()
		{
			References = new List<ReferenceInfo>();
			CompiledFiles = new List<ProjectFileInfo>();
			Pages = new List<PageInfo>();
			ResoucesFiles = new List<EmbeddedResources>();
		}

		public override string ToString()
		{
			return string.Format("{0}, {1}, {2}", ProjectName, ToolVersion, RootNamespace);
		}

		public override bool Equals(object obj)
		{
			if (obj != null && (obj is DetailedProjectInfo))
			{
				return (this.ToolVersion == (obj as DetailedProjectInfo).ToolVersion &&
					this.RootNamespace == (obj as DetailedProjectInfo).RootNamespace &&
					this.AssemblyName == (obj as DetailedProjectInfo).AssemblyName &&
					this.CompiledFiles.Count == (obj as DetailedProjectInfo).CompiledFiles.Count &&
					this.Pages.Count == (obj as DetailedProjectInfo).Pages.Count);

			}
			return false;
		}

		public override int GetHashCode()
		{
			return (ProjectName.Length + RootNamespace.Length + AssemblyName.Length + CompiledFiles.Count);
		}
	}

	public class ReferenceInfo
	{
		public string Name { get; set; }
		public bool IsSpecificVersion { get; set; }
		public string HintPath { get; set; }
		public string RequiredFramework { get; set; }

		public override string ToString()
		{
			return string.Format("{0}, {1}", Name, HintPath);
		}
	}

	public class ProjectFileInfo
	{
		public ProjectFileInfo() { IsSelected = false; SubType = string.Empty; }

		public string File { get; set; }
		public string DependentUpon { get; set; }
		public string SubType { get; set; }
		public bool IsSelected { get; set; }

		public override string ToString()
		{
			return string.Format("{0}, {1}", File, DependentUpon);
		}
	}

	public class PageInfo
	{
		public string Page { get; set; }
		public string SubType { get; set; }
		public string Generator { get; set; }

		public override int GetHashCode()
		{
			return Page.Length + Generator.Length + SubType.Length;
		}

		public override bool Equals(object obj)
		{
			if (obj != null && (obj is PageInfo))
			{
				var embRes = obj as PageInfo;
				return (this.Page == embRes.Page && this.Generator == embRes.Generator);
			}
			return false;
		}

		public override string ToString()
		{
			return string.Format("{0}, {1}", Page, Generator);
		}
	}

	public class EmbeddedResources
	{
		public string Name { get; set; }
		public string Generator { get; set; }
		public string LastGenOutput { get; set; }

		public override bool Equals(object obj)
		{
			if (obj != null && (obj is EmbeddedResources))
			{
				var embRes = obj as EmbeddedResources;
				return (this.Name == embRes.Name && this.Generator == embRes.Generator);
			}
			return false;
		}

		public override int GetHashCode()
		{
			return Name.Length + Generator == null ? 0 : Generator.Length + LastGenOutput == null ? 0 : LastGenOutput.Length;
		}

		public override string ToString()
		{
			return string.Format("{0}, {1}", Name, Generator);
		}
	}

	public class DuplicateStringInfo
	{
		public DuplicateStringInfo()
		{
			OccurrencesInFile = new Dictionary<string, int>();
		}
		public string ResourceString { get; set; }
		public string ResourceName { get; set; }
		
		public Dictionary<string, int> OccurrencesInFile { get; set; }

		public override string ToString()
		{
			return string.Format("{0} - {1}", ResourceName, ResourceString);
		}
	}
}
